<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>错误的集合</title>
</head>

<body>
  <script>
    function findErrorNums(nums) {
      let s = [...new Set(nums)].reduce((a, b) => a + b),
        l = nums.length
      return [nums.reduce((a, b) => a + b) - s, ((1 + l) * l) / 2 - s]
    };
    console.log(findErrorNums([1, 2, 2, 4]))
  </script>
</body>

</html>